#Include ..\baseHandle.ahk

class SetVar extends BaseHandle {

  static Handle(parsed) {
    value := parsed.extra[1]
    switch parsed.target {
      case 'light':
        _setLight(value)
      case 'volume':
        _setVolume(value)
      default: return this.Fail('no var.')
    }
    return this.Succ(value, 'x')

    _setLight(v) {
      Run(A_ComSpec
        ' /c "WMIC /NAMESPACE:\\root\wmi PATH WmiMonitorBrightnessMethods WHERE "Active=TRUE" CALL WmiSetBrightness Brightness='
        v ' Timeout=0"', , 'Hide')
    }

    _setVolume(v) {
      if v = 0 {
        Send("{Volume_Mute}")
      } else if v > 0
        Send("{Volume_Up}")
      else
        Send("{Volume_Down}")
    }
  }

  static Spec() {
    return {
      cmd: 'set',
      desc: '设置值',
      format: 'set <target> <value>',
      args: {
        desc: '',
        isOptional: false,
        cacheable: true,
        generator: {
          script: '',
          postProcess: (*) => ['volume', 'light']
        }
      },
      extra: {
        isEnable: true,
        desc: '值'
      }
    }
  }
}